﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Quickly.Certs.EntityFrameworkCore
{
    public class DesignTimeBuilderExtensions
    {
        public static IServiceProvider BuildDesignTimeServices(string[] args, string databaseType)
        {
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddCommandLine(args).AddEnvironmentVariables();
            var configuration = configurationBuilder.Build();

            var services = new ServiceCollection();
            services.AddScoped<IConfiguration>(sp => configuration);
            services.Configure<DatabaseOption>(option => option.Type = databaseType);
            services.AddDbContext<CertsContext>(EntityFrameworkCoreBuilderExtensions.BuildConfigureDatabase("Default"));

            var serviceProvider = services.BuildServiceProvider();

            return serviceProvider;
        }
    }
}
